// This is a part of the Microsoft Foundation Classes C++ library.
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
// This source code is only intended as a supplement to the
// Microsoft Foundation Classes Reference and related
// electronic documentation provided with the library.
// See these sources for detailed information regarding the
// Microsoft Foundation Classes product.

#pragma once

#include <vector>

#ifdef __PBBIM_BASE_UI__
#define BASEUIPORT __declspec(dllexport)
#else
#define BASEUIPORT
#endif

struct GePoint3d
{
    double x,y,z;
public:
    double operator [](int idx) const
    {
        return *(double *)&x;
    }
    double &operator [](int idx)
    {
        return *(double *)&x;
    }
    double *asDblPointer()
    {
        return &x;
    }
};

interface IPropCustomDialogInterface
{
    virtual void callDialogInterface(CMFCPropertyGridProperty& prop, CMFCPropertyGridProperty *pParent) = 0;
};

interface IPropToUpdatingBySubProp
{
public:
    void updateBySubProp(CMFCPropertyGridProperty& prop, CMFCPropertyGridProperty *pParent)
    {
        _updateBySubProp(prop, pParent);
    }
protected:
    virtual void _updateBySubProp(CMFCPropertyGridProperty& prop, CMFCPropertyGridProperty *pParent) = 0;
};

class BASEUIPORT PBBimCheckBoxProp : public CMFCPropertyGridProperty
{
public:
	PBBimCheckBoxProp(const CString& strName, BOOL bCheck, LPCTSTR lpszDescr = NULL, DWORD dwData = 0);

protected:
	virtual BOOL OnEdit(LPPOINT /*lptClick*/) { return TRUE; }
	virtual void OnDrawButton(CDC* /*pDC*/, CRect /*rectButton*/) {}
	//virtual void OnDrawValue(CDC* /*pDC*/, CRect /*rect*/) {}
	virtual BOOL HasButton() const { return FALSE; }

	virtual BOOL PushChar(UINT nChar);
	virtual void OnDrawCheckBox(CDC * pDC, CRect rectCheck, BOOL bChecked);
	virtual void OnDrawName(CDC* pDC, CRect rect);
	virtual void OnDrawValue(CDC* pDC, CRect rect);
	virtual void OnClickName(CPoint point);
	//virtual BOOL OnDblClk(CPoint point);

	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
		/*	{
				int kkk = 0;
			}*/

protected:
	CRect m_rectCheck;
};

class BASEUIPORT PBBimPreciseProp : public CMFCPropertyGridProperty
{
    // Construction
public:
    // Group constructor
    PBBimPreciseProp(const CString& strGroupName, DWORD_PTR dwData = 0, BOOL bIsValueList = FALSE);
    // Simple property
    PBBimPreciseProp(const CString& strName, LPCTSTR varValue, LPCTSTR lpszDescr = NULL, DWORD_PTR dwData = 0,
        LPCTSTR lpszEditMask = NULL, LPCTSTR lpszEditTemplate = NULL, LPCTSTR lpszValidChars = NULL);
    virtual ~PBBimPreciseProp();
};

class BASEUIPORT PBBimPasswordProp : public CMFCPropertyGridProperty
{
public:
	PBBimPasswordProp(const CString& strName, const CString& strPassword, LPCTSTR lpszDescr = NULL, DWORD dwData = 0);

protected:
	virtual CWnd* CreateInPlaceEdit(CRect rectEdit, BOOL& bDefaultFormat);
	virtual CString FormatProperty();
};

class BASEUIPORT PBBimSliderProp : public CMFCPropertyGridProperty
{
public:
	PBBimSliderProp(const CString& strName, long nValue, LPCTSTR lpszDescr = NULL, DWORD dwData = 0);

	virtual BOOL OnUpdateValue();

protected:
	virtual CWnd* CreateInPlaceEdit(CRect rectEdit, BOOL& bDefaultFormat);
	virtual BOOL OnSetCursor() const { return FALSE; /* Use default */ }
};

class BASEUIPORT PBBimBoundedNumberPairProp : public CMFCPropertyGridProperty
{
public:
	PBBimBoundedNumberPairProp(const CString& strGroupName, int nMinValue1, int nMaxValue1, int nMinValue2, int nMaxValue2, DWORD_PTR dwData = 0, BOOL bIsValueList = FALSE);

	virtual BOOL OnUpdateValue();

private:
	int m_nMinValue1;
	int m_nMaxValue1;
	int m_nMinValue2;
	int m_nMaxValue2;
};

class BASEUIPORT PBBimBoundedNumberSubProp : public CMFCPropertyGridProperty
{
public:
	PBBimBoundedNumberSubProp(const CString& strName, const COleVariant& varValue, int nMinValue, int nMaxValue, LPCTSTR lpszDescr = NULL);
    void setHook(IPropToUpdatingBySubProp *pHook);
	virtual BOOL OnUpdateValue();
private:
	int m_nMinValue;
	int m_nMaxValue;
    IPropToUpdatingBySubProp *m_pHook;
};

/////////////////////////////////////////////////////////////////////////////
// PBBimPropSliderCtrl window

class BASEUIPORT PBBimPropSliderCtrl : public CSliderCtrl
{
// Construction
public:
	PBBimPropSliderCtrl(PBBimSliderProp* pProp, COLORREF clrBack);

// Attributes
protected:
	CBrush m_brBackground;
	COLORREF m_clrBack;
	PBBimSliderProp* m_pProp;

// Implementation
public:
	virtual ~PBBimPropSliderCtrl();

protected:
	//{{AFX_MSG(PBBimPropSliderCtrl)
	afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor);
	//}}AFX_MSG
	afx_msg void HScroll(UINT nSBCode, UINT nPos);

	DECLARE_MESSAGE_MAP()
};

class BASEUIPORT PBBimIconListProp : public CMFCPropertyGridProperty
{
public:
	PBBimIconListProp(const CString& strName, const CImageList& imageListIcons, int nSelectedIcon, CStringList* plstIconNames = NULL, LPCTSTR lpszDescr = NULL, DWORD dwData = 0);

protected:
	virtual CWnd* CreateInPlaceEdit(CRect rectEdit, BOOL& bDefaultFormat);
	virtual CComboBox* CreateCombo(CWnd* pWndParent, CRect rect);
	virtual void OnDrawValue(CDC* pDC, CRect rect);

	CMFCToolBarImages m_imageListIcons;
	CStringList m_lstIconNames;
};

/////////////////////////////////////////////////////////////////////////////
// PBBimIconCombo window

class BASEUIPORT PBBimIconCombo : public CComboBox
{
// Construction
public:
	PBBimIconCombo(CMFCToolBarImages& imageListIcons, CStringList& lstIconNames);

// Attributes
protected:
	CMFCToolBarImages& m_imageListIcons;
	CStringList& m_lstIconNames;

// Implementation
public:
	virtual ~PBBimIconCombo();

protected:
	//{{AFX_MSG(PBBimIconCombo)
	afx_msg void OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct);
	afx_msg void OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct);
	//}}AFX_MSG

	DECLARE_MESSAGE_MAP()
};

class BASEUIPORT PBBimComboBoxExProp : public CMFCPropertyGridProperty
{
public:
	PBBimComboBoxExProp(const CString& strName, const CString& strValue, LPCTSTR lpszDescr = NULL, DWORD dwData = 0, CImageList* pImageList = NULL);

	BOOL AddOption(LPCTSTR lpszOption, int nIcon = -1, int nIndent = 0);

protected:
	virtual CComboBox* CreateCombo(CWnd* pWndParent, CRect rect);
	virtual BOOL OnEdit(LPPOINT lptClick);

	CImageList* m_pImageList;
	CArray<int, int> m_lstIcons;
	CArray<int, int> m_lstIndents;
};

class BASEUIPORT PBBimOwnerDrawDescrProp : public CMFCPropertyGridProperty
{
public:
	PBBimOwnerDrawDescrProp(const CString& strName, const COleVariant& varValue);

protected:
	virtual void OnDrawDescription(CDC* pDC, CRect rect);
};

class BASEUIPORT PBBimTwoButtonsProp : public CMFCPropertyGridProperty
{
public:
	PBBimTwoButtonsProp(const CString& strName, const COleVariant& varValue);

protected:
	virtual BOOL HasButton() const { return TRUE; }
	virtual void AdjustButtonRect();
	virtual void OnClickButton(CPoint point);
	virtual void OnDrawButton(CDC* pDC, CRect rectButton);

	CImageList m_images;
};

class BASEUIPORT PBBimCustomDlgProp : public CMFCPropertyGridProperty
{
public:
	PBBimCustomDlgProp(const CString& strName, const COleVariant& varValue);
    ~PBBimCustomDlgProp();
    void setHook(IPropCustomDialogInterface* hook);

protected:
	virtual BOOL HasButton() const { return TRUE; }
	virtual void OnClickButton(CPoint point);
private:
    IPropCustomDialogInterface *m_pHook;
};

class BASEUIPORT PBBimPointNDProp : public CMFCPropertyGridProperty
{
public:
    PBBimPointNDProp(const CString &strName);
    ~PBBimPointNDProp();
    BOOL init(int nDim, double pt[], const CString subName[]);
    void updateFromPointND(int nDim, double pt[]);
    void setHook(IPropCustomDialogInterface *hook);
    void updateFromSubItem(CMFCPropertyGridProperty& subItem);
    IPropCustomDialogInterface* hook() const;
protected:
    IPropCustomDialogInterface *m_pHook;
private:
    enum 
    {
        eMaxDimesion = 8,
    };
    int m_nDim;
    double m_pt[eMaxDimesion];
};

class BASEUIPORT PPBimPoint3DListProp : public CMFCPropertyGridProperty
{
public:
    PPBimPoint3DListProp(const CString& strName);
    ~PPBimPoint3DListProp();
    BOOL init(int nNum, int curIdx, GePoint3d pts[]);
    void setHook(IPropCustomDialogInterface *hook);
    void updateFromSubItem(CMFCPropertyGridProperty& subItem);
    void updateFromPoint3DList(int nNum, GePoint3d pts[]);
    const GePoint3d &operator [](int idx) const;
    GePoint3d &operator [](int idx);
    void  updateBySubProp(CMFCPropertyGridProperty& subProp);
protected:
    IPropCustomDialogInterface *m_pHook;
private:
    int  m_curIdx;
    int  m_nNum;
    GePoint3d *m_pts; // should include m_nNum+1's GePoint3d
};
